//
// Created by xiaoma on 1/27/21.
//
#define CATCH_CONFIG_MAIN
#include "catch/catch_amalgamated.hpp"
#include <cstdio>
#include "source/util/BufferedInputStream.h"
#include "source/code/BinaryFileParser.h"
#include "runtime/Interpreter.h"
#include "source/object/Universe.h"

TEST_CASE("Read int for BufferedInputStream") {
    BufferedInputStream inputStream("/home/xiaoma/code/c++_project/horse_vm/test/test.pyc");
    char tmp[16];
    sprintf(tmp, "%x", inputStream.readInt());
    std::string s = tmp;
    CHECK(s == "a0df303");
}

TEST_CASE("aa") {
    BufferedInputStream inputStream("/home/xiaoma/code/c++_project/horse_vm/test/test.pyc");
    BinaryFileParser parser(&inputStream);
    CodeObject* codeObject = parser.parse();
    Interpreter interpreter;
    interpreter.run(codeObject);
}

TEST_CASE("Test if") {
    Universe::genesis();
    BufferedInputStream inputStream("/home/xiaoma/code/c++_project/horse_vm/test/test_if.pyc");
    BinaryFileParser parser(&inputStream);
    CodeObject* codeObject = parser.parse();
    Interpreter interpreter;
    interpreter.run(codeObject);
}

TEST_CASE("Test while") {
    Universe::genesis();
    BufferedInputStream inputStream("/home/xiaoma/code/c++_project/horse_vm/test/test_while.pyc");
    BinaryFileParser parser(&inputStream);
    CodeObject* codeObject = parser.parse();
    Interpreter interpreter;
    interpreter.run(codeObject);
}

TEST_CASE("Test var") {
    Universe::genesis();
    BufferedInputStream inputStream("/home/xiaoma/code/c++_project/horse_vm/test/test_var.pyc");
    BinaryFileParser parser(&inputStream);
    CodeObject* codeObject = parser.parse();
    Interpreter interpreter;
    interpreter.run(codeObject);
}

TEST_CASE("Test continue and break") {
    Universe::genesis();
    BufferedInputStream inputStream("/home/xiaoma/code/c++_project/horse_vm/test/test_continue_break.pyc");
    BinaryFileParser parser(&inputStream);
    CodeObject* codeObject = parser.parse();
    Interpreter interpreter;
    interpreter.run(codeObject);
}

TEST_CASE("Test multi while") {
    Universe::genesis();
    BufferedInputStream inputStream("/home/xiaoma/code/c++_project/horse_vm/test/test_multi_while.pyc");
    BinaryFileParser parser(&inputStream);
    CodeObject* codeObject = parser.parse();
    Interpreter interpreter;
    interpreter.run(codeObject);
}
